from django.urls import path,include
from .views.Apiviews import ProductApiView
from .views.Gviews import ProductGAPIView,ProductGdetailAPIView
from .views.mixins import ProductListMixin,ProductDetailMixin
from .views.GenericMixin import ProductGListMixin
from .views.viewsetView import ProductViewset,ProductGenriceViewset,ProductModelViewset,ProductReadOnlyModelViewset
from .views.users import registerUser
# from .views.login import LoginView,GetCSRFTokenView

from rest_framework import routers
# 导入JWT认证视图
from rest_framework_simplejwt.views import TokenObtainPairView,TokenRefreshView,TokenVerifyView

# 自动生成路由，仅限ViewSet视图使用
# 注意：ViewSet视图必须继承自ViewSet，而不是APIView，否则无法自动生成路由
# 实例化路由对象
# router = routers.SimpleRouter()

# 配置default路由器，默认路由会自动生成根路由，即/，用于查看所有可用的API
router = routers.DefaultRouter()

# 注册路由
# router.register("viewset", ProductViewset,basename="viewset")
# router.register("Gviewset", ProductGenriceViewset,basename="Gviewset")
router.register("Mviewset", ProductModelViewset,basename="Mviewset")
# router.register("Rviewset", ProductReadOnlyModelViewset,basename="Rviewset")

urlpatterns = [
    path("products/", ProductApiView.as_view()),  # 注意这里是as_view()，不是as_view
    path("G_products/", ProductGAPIView.as_view()),  
    path("G_products/<int:pk>/", ProductGdetailAPIView.as_view()),  # pk是主键，用于获取指定的商品数
    path("mixin/", ProductListMixin.as_view()),
    path("mixin/<int:pk>/", ProductDetailMixin.as_view()),
    path("G_mixin/", ProductGListMixin.as_view()),
    path("Mviewset/<int:pk>/reviews/", ProductModelViewset.as_view({"get":"reviews"})),  
    
    #------------------用户路由
    # path("get_csrf_token/", GetCSRFTokenView.as_view()),  # 获取CSRF token
    # path("login/", LoginView.as_view()),  
    path("token/", TokenObtainPairView.as_view()),  
    path("register/", registerUser),
    
    #-----------------------------------------------
    # 自动自成的路由
    path("", include(router.urls)),
    #---------------------------------------------------
    # path("viewset/", ProductViewset.as_view({"get":"list","post":"create"})), 
    # path("viewset/<int:pk>/", ProductViewset.as_view({"get":"retrieve","put":"update",  "patch":"partial_update","delete":"destroy"})),
    
    
    
]